<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="液柱深度 (m)" prop="yzsd">
				<u-input :border="border" placeholder="液柱深度 (m)" v-model="model.yzsd" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="套管内直径 (mm)" prop="tgnzj">
				<u-input :border="border" placeholder="套管内直径 " v-model="model.tgnzj" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="油管本体直径 (mm)" prop="yzsd">
				<u-input :border="border" placeholder="油管本体直径" v-model="model.ygbtzj" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<view>
					<span>压井液用量-套管/油管内容积计算量的值为：</span>
					<strong v-if="model.result"> {{model.result}} m³</strong>
				</view>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">V环 = πH(D套内²-D油本²)</view>
				<view class="u-item-desc">
				式中：<br>
				V环 —套管内环空容积，m3；<br>
				H—液柱深度，m；<br>
				D套内—套管内直径，mm；<br>
				D油本—油管本体直径，mm。<br>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					yzsd: '',
					tgnzj: '',
					ygbtzj: '',
					result: ''
				},
				rules: {
					yzsd: [{
						required: true,
						message: '请填写液柱深度',
						trigger: 'blur'
					}],
					tgnzj: [{
						required: true,
						message: '请填写套管/油管内直径',
						trigger: 'blur'
					}],
					ygbtzj: [{
						required: true,
						message: '请填写油管本体直径',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,

			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
							
							const H = parseFloat(this.model.yzsd);
							const D=parseFloat(this.model.tgnzj)*0.001;
							const DZ=parseFloat(this.model.ygbtzj)*0.001;
							
							 //V环 = 0.785*10^(-6)* H(D套内²-D油本²)
							 
							this.model.result = (H*(Math.PI*(Math.pow(D/2,2)-Math.pow(DZ/2,2)))).toFixed(4);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>